<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>教师管理</title>

    <%@ include file="base.jsp" %>

    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="css/x-admin.css" media="all">
    <link rel="stylesheet" href="css/pag.css" media="all">
    <link rel="stylesheet" href="css/query.css" media="all">
</head>

<body>
<div class="x-nav"><span class="layui-breadcrumb"> <a><cite>教师管理</cite></a> <a><cite>教师信息管理</cite></a> </span> <a
        class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
        href="admin/teacherController?fun=index" title="刷新"><i class="layui-icon"
                                                               style="line-height:30px">ဂ</i></a></div>
<div class="x-body">
    <div style="margin-bottom: 10px">
        <fieldset class="queryCss">
            <legend>查询条件</legend>
            <label class="layui-form-label">教师名称：</label>
            <input type="text" value="${tname}" name="tname" id="tname" class="layui-input-inline"/>
            <button value="查询" class="layui-btn" onclick="queryInfo()">关键字查询</button>
            <button value="addBtn" class="layui-btn"
            <%--                    onclick="data_management_look('添加教师信息','teacher_add.jsp?total=${page.total}&pages=${page.pages}','600','600','500');return false;">--%>
                    onclick="data_management_look('添加教师信息','admin/teacherController?total=${page.total}&pages=${page.pages}&fun=list','600','600','500');return false;">
                添加
            </button>
        </fieldset>
    </div>
    <div class="tools">
        <ul class="toolbar">
            <li>
                <span onclick="deleteSelect()"><span><img src="images/t03.png"/></span>批量删除</span>
            </li>
            <li><span onclick="batchExport()"><img src="images/t09.png"/>批量导出</span></li>
            <li><span onclick="location.href='<%=request.getContextPath()%>/admin/bathExportController?fun=teacher&eall=1'">
                <img src="images/t09.png"/>导出所有</span>
            </li>
        </ul>
        <span class="x-right" style="line-height:25px">共有数据：<span id="count">${page.total}</span> 条</span></xblock>
    </div>
    <table class="tablelist">
        <thead>
        <tr>
            <th><input onclick="selectAll()" type="checkbox" name="controlAll" style="controlAll" id="controlAll">
            </th>
            <th>教师id</th>
            <th> 教师名称</th>
            <th> 性别</th>
            <th> 手机号</th>
            <th> email</th>
            <th> 所属学院</th>
            <th> 操作</th>
        </tr>
        </thead>
        <tbody id="x-link">
        <form action="admin/bathExportController" method="post" id="export">
            <c:forEach var="i" items="${page.list}">
                <tr>
                    <td>
                        <input type="hidden" name="fun" value="teacher">
                        <input class="selected" type="checkbox" value="${i.tid}" name="selected">
                    </td>
                    <td>${i.tid}</td>
                    <td>${i.tname}</td>
                    <td>${i.tsex}</td>
                    <td>${i.tphone}</td>
                    <td>${i.temail}</td>
                    <td>${i.cname}</td>
                    <td class="td-manage"><a title="处理" href="javascript:;"
                                             onclick="data_management_look('修改','admin/teacherController?tid=${i.tid}&cid=${i.cid}&pn=${page.pageNo}&fun=updatePage','4','','510')"
                                             class="ml-5"
                                             style="text-decoration:none"> <i class="layui-icon">&#xe642;</i> </a> <a
                            title="删除"
                            href="javascript:;"
                            onclick="data_management_del(${i.tid},${page.pageNo})"
                            style="text-decoration:none">
                        <i class="layui-icon">&#xe640;</i>
                    </a></td>
                </tr>
            </c:forEach>
        </form>
        </tbody>
    </table>
    <c:if test="${empty tname}">
        <div class="page" v-show="show">
            <div class="pagelist">
            <span class="jump">
                <a href="admin/teacherController?fun=index&pageNo=${page.pageNo -1}">上一页</a>
            </span>

                <c:forEach var="p" begin="1" end="${page.pages}">
                    <a href="admin/teacherController?fun=index&pageNo=${p}">
                <span class="jump"
                      <c:if test="${page.pageNo == p}">style="background-color: skyblue" </c:if>
                >
                        ${p}
                </span>
                    </a>
                </c:forEach>
                <span class="jump">
                <c:if test="${page.pageNo +1 > page.pages}">
                    <a href="admin/teacherController?fun=index&pageNo=${page.pageNo}">下一页</a>
                </c:if>
                <c:if test="${page.pageNo +1 <= page.pages}">
                    <a href="admin/teacherController?fun=index&pageNo=${page.pageNo+1}">下一页</a>
                </c:if>

            </span>
                <span class="jumppoint">跳转到：</span>
                <span class="jumpinp">
          <input type="text" id="topage">
        </span> <span class="jump gobtn" onclick="topage(${page.pages})">GO</span></div>
        </div>
    </c:if>

    <c:if test="${!empty tname}">
        <div class="page" v-show="show">
            <div class="pagelist">
            <span class="jump">
                <a href="admin/teacherController?fun=query&tname=${tname}&pageNo=${page.pageNo -1}">上一页</a>
            </span>

                <c:forEach var="p" begin="1" end="${page.pages}">
                    <a href="admin/teacherController?fun=query&tname=${tname}&pageNo=${p}">
                <span class="jump"
                      <c:if test="${page.pageNo == p}">style="background-color: skyblue" </c:if>
                >
                        ${p}
                </span>
                    </a>
                </c:forEach>
                <span class="jump">
                <c:if test="${page.pageNo +1 > page.pages}">
                    <a href="admin/teacherController?fun=query&tname=${tname}&pageNo=${page.pageNo}">下一页</a>
                </c:if>
                <c:if test="${page.pageNo +1 <= page.pages}">
                    <a href="admin/teacherController?fun=query&tname=${tname}&pageNo=${page.pageNo+1}">下一页</a>
                </c:if>

            </span>
                <span class="jumppoint">跳转到：</span>
                <span class="jumpinp">
          <input type="text" id="topage2">
        </span> <span class="jump gobtn" onclick="topage2(${page.pages})">GO</span></div>
        </div>
    </c:if>

</div>
<br/>
<br/>
<br/>
<script src="./lib/layui/layui.js" charset="utf-8"></script>
<script src="./js/x-layui.js" charset="utf-8"></script>

<script src="js/jquery2.js" charset="utf-8"></script>
<script src="js/js.js" charset="utf-8"></script>
<script>
    layui.use(['element', 'laypage', 'layer', 'form'], function () {
        $ = layui.jquery;//jquery
        lement = layui.element();//面包导航
        laypage = layui.laypage;//分页
        layer = layui.layer;//弹出层
        form = layui.form();//弹出层
    });

    // 编辑
    function data_management_look(title, url, id, w, h) {
        x_admin_show(title, url, w, h);
    }

</script>
<script>
    $('.tablelist tbody tr:odd').addClass('odd');
</script>
<script>
    function batchExport() {
        let $selected = $('.selected:checked');
        if ($selected.length == 0) {
            alert('请先选择要导出的数据');
        } else {
            $('#export').submit();
        }
    }

    function data_management_del(tid, pn) {
        layer.confirm(
            '您确定删除当前教师？(此操作会强制删除该教师所有信息！)',
            ['确定', "取消"],
            function () {
                $.ajax({
                    url: '<%=request.getContextPath()%>/admin/teacherController',
                    data: {
                        "fun": 'delete',
                        "tid": tid,
                        "pn": pn
                    },
                    success() {
                        <c:if test="${empty tname}">
                        location.href = "<%=request.getContextPath()%>/admin/teacherController?fun=index";
                        </c:if>
                        <c:if test="${!empty tname}">
                        location.href = "<%=request.getContextPath()%>/admin/teacherController?fun=query&tname=${tname}";
                        </c:if>
                    }
                })
            }
        )
    }

    function deleteSelect() {
        layer.confirm(
            '您确定删除所有选中的教师？(此操作会强制删除所有选中的的所有信息！)',
            ['确定', "取消"],
            function () {
                var ids = [];
                $('.selected:checked').each(function () {
                    ids.push($(this).val())
                })
                $.ajax({
                    url: '<%=request.getContextPath()%>/admin/teacherController',
                    data: {
                        "ids": ids,
                        "fun": "deleteSelect"
                    },
                    success() {
                        <c:if test="${empty tname}">
                        location.href = "<%=request.getContextPath()%>/admin/teacherController?fun=index";
                        </c:if>
                        <c:if test="${!empty tname}">
                        location.href = "<%=request.getContextPath()%>/admin/teacherController?fun=query&tname=${tname}";
                        </c:if>
                    }
                })
            }
        )
    }

    function topage(pages) {
        let toPageNo = $('#topage').val();
        if (toPageNo > pages) {
            toPageNo = pages
        }
        $.ajax({
            url: '<%=request.getContextPath()%>/admin/teacherController',
            data: {
                "fun": 'index',
                "pageNo": toPageNo
            },
            success(data) {
                $('body').html(data)
            }
        })
    }


    function topage2(pages) {
        let toPageNo = $('#topage2').val();
        if (toPageNo > pages) {
            toPageNo = pages
        }
        $.ajax({
            url: '<%=request.getContextPath()%>/admin/teacherController',
            data: {
                "fun": 'query',
                "pageNo": toPageNo,
                "tname": $('#tname').val()
            },
            success(data) {
                $('body').html(data)
            }
        })
    }

    function queryInfo() {
        var tname = $('#tname').val()
        location.href = '<%=request.getContextPath()%>/admin/teacherController?fun=query&tname=' + tname
    }
</script>
</body>

</html>